package com.jl.jlapp.mvp.fragment;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.jl.jlapp.R;
import com.jl.jlapp.eneity.ImageBean;
import com.jl.jlapp.mvp.activity.PhotoViewActivity;
import com.jl.jlapp.utils.MimeTypeUtils;
import com.jl.jlapp.utils.loader.Loader;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.PermissionNo;
import com.yanzhenjie.permission.PermissionYes;
import com.yanzhenjie.permission.Rationale;
import com.yanzhenjie.permission.RationaleListener;
import com.yanzhenjie.permission.Request;
import com.yzs.imageshowpickerview.ImageShowPickerBean;
import com.yzs.imageshowpickerview.ImageShowPickerListener;
import com.yzs.imageshowpickerview.ImageShowPickerView;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.PicassoEngine;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.MultipartBody.Part;
import okhttp3.RequestBody;

import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;

public class AddVatInvoicePicFragment extends Fragment {
    private static final int REQUEST_CODE_CHOOSE = 233;
    List<ImageBean> list;
    MultipartBody.Part[] partList = new MultipartBody.Part[10];
    @BindView(R.id.it_picker_view)
    ImageShowPickerView pickerView;
    private RationaleListener rationaleListener = new RationaleListener() {
        public void showRequestPermissionRationale(int paramAnonymousInt, Rationale paramAnonymousRationale) {
            paramAnonymousRationale.resume();
        }
    };
    List<String> realPicUrlList = new ArrayList();

    @PermissionNo(300)
    private void getPermissionNo(List<String> paramList) {
        Toast.makeText(getActivity(), "未授权", Toast.LENGTH_SHORT).show();
    }

    @PermissionYes(300)
    private void getPermissionYes(List<String> paramList) {
    }

    private void photo(List<String> paramList) {
        this.partList = new MultipartBody.Part[10];
        int i = 0;
        while (i < paramList.size()) {
            Object localObject = new File((String) paramList.get(i));
            if (localObject != null) {
                RequestBody localRequestBody = RequestBody.create(MediaType.parse(MimeTypeUtils.getMimeType((File) localObject)), (File) localObject);
                Part part = Part.createFormData("file", ((File) localObject).getName(), localRequestBody);
                this.partList[i] = part;
            }
            i += 1;
        }
    }

    public String getRealFilePath(Context paramContext, Uri paramUri) {
        if (paramUri == null) {
            return null;
        }
        String str = paramUri.getScheme();
        String localObject2 = null;
        String localObject3 = null;
        String localObject1 = null;
        if (str == null) {
            localObject1 = paramUri.getPath();
        }
        this.realPicUrlList.add(localObject1);
        if ("file".equals(str)) {
            localObject1 = paramUri.getPath();
        } else {
            localObject1 = localObject3;
            if ("content".equals(str)) {
                Cursor cursor = paramContext.getContentResolver().query(paramUri, new String[]{"_data"}, null, null, null);
                localObject1 = localObject3;
                if (cursor != null) {
                    localObject1 = localObject2;
                    if (cursor.moveToFirst()) {
                        int i = cursor.getColumnIndex("_data");
                        localObject1 = localObject2;
                        if (i > -1) {
                            localObject1 = paramContext.getString(i);
                        }
                    }
                    cursor.close();
                }
            }
        }
        return (String) localObject1;
    }

    public void handleImgPicker() {
        this.list = new ArrayList();
        this.pickerView.setImageLoaderInterface(new Loader());
        this.pickerView.setNewData(this.list);
        this.pickerView.setShowAnim(true);
        this.pickerView.setMaxNum(2);
        this.pickerView.setOneLineShowNum(5);
        this.pickerView.setmDelLabel(2131165417);
        this.pickerView.setmAddLabel(2131165621);
        this.pickerView.setmPicSize(200);
        this.pickerView.setPickerListener(new ImageShowPickerListener() {
            public void addOnClickListener(int paramAnonymousInt) {
                Matisse.from(AddVatInvoicePicFragment.this.getActivity()).choose(MimeType.of(MimeType.JPEG, new MimeType[]{MimeType.PNG})).countable(true).maxSelectable(paramAnonymousInt + 1).restrictOrientation(SCREEN_ORIENTATION_UNSPECIFIED).gridExpectedSize(300).thumbnailScale(0.85F).imageEngine(new PicassoEngine()).theme(R.style.Matisse_Dracula).forResult(233);
            }

            public void delOnClickListener(int paramAnonymousInt1, int paramAnonymousInt2) {
                AddVatInvoicePicFragment.this.realPicUrlList.remove(paramAnonymousInt1);
            }

            public void picOnClickListener(List<ImageShowPickerBean> paramAnonymousList, int paramAnonymousInt1, int paramAnonymousInt2) {
                Intent intent = new Intent(AddVatInvoicePicFragment.this.getActivity(), PhotoViewActivity.class);
                intent.putExtra("picUrl", (String) AddVatInvoicePicFragment.this.realPicUrlList.get(paramAnonymousInt1));
                intent.putExtra("flag", 1);
                AddVatInvoicePicFragment.this.startActivity(intent);
            }
        });
        this.pickerView.show();
        AndPermission.with(this).requestCode(300).permission(new String[]{"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"}).rationale(this.rationaleListener).callback(this).start();
        this.pickerView.getDataList();
    }

    public void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent) {
        super.onActivityResult(paramInt1, paramInt2, paramIntent);
        if (paramInt1 == 233) {
            getActivity();
            List<Uri> uris = Matisse.obtainResult(paramIntent);
            if (paramInt2 == -1) {
                if (((List) uris).size() != 1) {
                    return;
                }
                this.pickerView.addData(new ImageBean(getRealFilePath(getActivity(), uris.get(0))));
            }
            ArrayList arrayList = new ArrayList();
            Object localObject =  uris.iterator();
            while (((Iterator) localObject).hasNext()) {
                Uri localUri = (Uri) ((Iterator) localObject).next();
                arrayList.add(new ImageBean(getRealFilePath(getActivity(), localUri)));
            }
            this.pickerView.addData(arrayList);
        }
    }

    public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
        View inflate = paramLayoutInflater.inflate(R.layout.fragment_add_vat_invoice_pic, null, false);
        ButterKnife.bind(this, inflate);
        handleImgPicker();
        return inflate;
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/fragment/AddVatInvoicePicFragment.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */